package com.kexio.pay.enums;

/**
 * 退款状态枚举
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public enum RefundStatus {
    
    /**
     * 退款申请中
     */
    PENDING("PENDING", "退款申请中"),
    
    /**
     * 退款处理中
     */
    PROCESSING("PROCESSING", "退款处理中"),
    
    /**
     * 退款成功
     */
    SUCCESS("SUCCESS", "退款成功"),
    
    /**
     * 退款失败
     */
    FAILED("FAILED", "退款失败"),
    
    /**
     * 退款已取消
     */
    CANCELLED("CANCELLED", "退款已取消");
    
    private final String code;
    private final String description;
    
    RefundStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 根据代码获取枚举
     */
    public static RefundStatus fromCode(String code) {
        for (RefundStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown refund status code: " + code);
    }
    
    /**
     * 是否为最终状态
     */
    public boolean isFinalStatus() {
        return this == SUCCESS || this == FAILED || this == CANCELLED;
    }
    
    /**
     * 是否为成功状态
     */
    public boolean isSuccess() {
        return this == SUCCESS;
    }
    
    /**
     * 是否为失败状态
     */
    public boolean isFailure() {
        return this == FAILED || this == CANCELLED;
    }
}
